<template>
  <div class="type-management">
    <p>还没做好，手动修改吧。</p>
    <p>点击<a href="https://mysql.ddltech.top/" target="_blank">这里</a>编辑数据库</p>
    <mu-divider />
    <p>类型一致性检查</p>
    <mu-button color="primary" @click="check()">点击检查</mu-button>
    <p>检查结果：{{ checkResult }}</p>
    <mu-divider />
    <p>类型一致性修复</p>
    <mu-button color="success" @click="fix()">点击修复</mu-button>
    <p>修复结果：{{ fixResult }}</p>
  </div>
</template>

<script>
import api from '@/api'

const MAX_LEVEL = 2

export default {
  name: 'TypeManagement',
  data() {
    return {
      checkResult: '(未执行)',
      fixResult: '(未执行)'
    }
  },
  methods: {
    async check() {
      try {
        const data = await api.checkConsistent(MAX_LEVEL)
        if (data.result) {
          this.checkResult = '正常，' + data.message
        } else {
          this.checkResult = '可修复，' + data.message
        }
      } catch (err) {
        this.checkResult = '不可修复，' + err.message
      }
    },
    async fix() {
      try {
        const data = await api.fixConsistent(MAX_LEVEL)
        this.fixResult = '成功，' + data.message
      } catch (err) {
        this.fixResult = '失败，' + err.message
      }
    }
  }
}
</script>

<style scoped>
.type-management {
  padding: 16px;
}
</style>
